package se.liu.oschi129.game.objects.enemies;

import se.liu.oschi129.animation.animationspace.AnimationSpace;
import se.liu.oschi129.game.objects.ObjectPlayer;
import se.liu.oschi129.world.model.World;
import se.liu.oschi129.world.objects.WorldMovableObject;
import se.liu.oschi129.world.objects.WorldObject;

/**
 * 
 * 
 * @author oschi129
 */
public class ObjectEnemyBird extends WorldMovableObject implements EnemyObject, DefeatableEnemyObject {

	private WorldObject target;
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - - Constructors - - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	public ObjectEnemyBird(double x, double y) {
		super(Type.SOFT, AnimationSpace.get("img_bird01"),true,x,y,40,32);
		setImageSpeed(0.5);
		target = null;
	}
	
	/**
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 * - - - - - - - - - - - Public methods - - - - - - - - - - 
	 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	 */
	
	@Override public void performDestructionAction(World world) {
		world.addObjectSynchronized(new ObjectEnemyDead(AnimationSpace.get("img_bird_death01"), getX(), getY(), getWidth(), getHeight()));
	}
	
	@Override public void performStepAction(World world) {
		super.performStepAction(world);
		if (target == null)
			target = world.objectExists(ObjectPlayer.class);
		else {
			if (getX() - target.getX() < 256)
				setHorizontalSpeed(-3);
		}
	}
	
}
